package com.catchu.pattern.creational.迭代器模式.b进阶.aggregate;

import com.catchu.pattern.creational.迭代器模式.b进阶.iterator.Iterator;
import com.catchu.pattern.creational.迭代器模式.b进阶.iterator.ListPayIterator;
import com.catchu.pattern.creational.迭代器模式.b进阶.model.PayModel;

import java.util.ArrayList;
import java.util.List;

/**
 * 使用集合方式实现的聚合对象
 */
public class ListPayAggregate extends BasicAggregate {

    /**
     * 底层使用集合实现
     */
    private List list = new ArrayList();

    @Override
    public Iterator createIterator() {
        return new ListPayIterator(this);
    }

    /**
     * 获取某个元素值
     * @param i
     * @return
     */
    public Object get(int i){
        Object result = null;
        if(i<this.list.size()){
            result = this.list.get(i);
        }
        return result;
    }

    /**
     * 获取集合长度
     * @return
     */
    public int size(){
        return this.list.size();
    }

    /**
     * 获取工资列表
     * @return
     */
    public List getList(){
        return list;
    }

    public void calcPay(){
        PayModel payModel = new PayModel();
        payModel.setName("张三");
        payModel.setSalary(3000.0);

        PayModel payModel2 = new PayModel();
        payModel2.setName("李四");
        payModel2.setSalary(4208.2);

        list.add(payModel);
        list.add(payModel2);
    }
}
